from django.db import models


# Create your models here.
class Casting(models.Model):
    class Meta:
        db_table = "casting"

    project_number = models.CharField(
        verbose_name="项目号",
        max_length=20,
    )
    draw_number = models.CharField(
        verbose_name="图号",
        max_length=20,
    )
    part_name = models.CharField(
        verbose_name="名称",
        max_length=100,
    )
    inspector = models.ForeignKey(
        verbose_name="检查员",
        to="user.User",
        on_delete=models.CASCADE,
        related_name="inspector",
        null=True,
    )
    inspect_date = models.DateField(verbose_name="检查日期", null=True)
    reviewer = models.ForeignKey(
        verbose_name="审核",
        to="user.User",
        on_delete=models.CASCADE,
        related_name="reviewer",
        null=True,
    )
    review_date = models.DateField(verbose_name="审核日期", null=True)


class CastingFilm(models.Model):
    class Meta:
        db_table = "casting_film"

    examined_area_number = models.CharField(
        verbose_name="部位编号",
        max_length=20,
    )
    film_number = models.CharField(
        verbose_name="底片编号",
        max_length=100,
    )
    film_density = models.FloatField(
        verbose_name="底片黑度(D)",
    )
    iqi = models.FloatField(
        verbose_name="像质指数",
    )
    thickness = models.FloatField(
        verbose_name="透照厚度(mm)",
    )
    evaluation = models.TextField(
        verbose_name="评定结果",
        blank=True,
    )
    once_rt_length = models.FloatField(
        verbose_name="一次透照长度(mm)",
    )
    note = models.TextField(
        verbose_name="备注",
        blank=True,
    )
    project = models.ForeignKey(
        verbose_name="项目", to="Casting", on_delete=models.CASCADE
    )
    image = models.ImageField(
        verbose_name="底片",
        upload_to="data/casting/",
    )
    
class CastingDefect(models.Model):
    class Meta:
        db_table="casting_defect"
        
    film = models.ForeignKey(
        verbose_name="底片",
        to="CastingFilm", on_delete=models.CASCADE
    )
    kind=models.CharField(
        verbose_name="缺陷类型",
        max_length=20
    )
    grade=models.IntegerField(
        verbose_name="缺陷等级",
        default=0
    )
    x=models.FloatField(
        verbose_name="横轴位置",
    )
    y=models.FloatField(
        verbose_name="纵轴位置",
    )
    w=models.FloatField(
        verbose_name="检测宽度",
    )
    h=models.FloatField(
        verbose_name="检测高度",
    )
